app.controller('NewsController', ['$scope', 'rssReader', 'chunk',
  function($scope, rssReader, chunk) {

    $scope.feedRowsLimit = 5;
    $scope.feedRows = [];

    $scope.increaseFeedsLimit = function(count) {
      $scope.feedRowsLimit += count || 5;
    };

    // Read RSS feeds, chunk it in rows and push it in the $scope.feeds array
    (function() {
      rssReader.read().then(function(data, rssConfig) {
        $scope.feedRows = chunk(data, 2);
      }, function(error, statusCode) {
        $scope.feedRows = [[{
          'title': 'Cannot read feeds.',
          'description': 'statusCode: ' + statusCode
        }]];
      });
    }());

  }
]);
